package com.rdc.jiajiadictionary.translate;

import android.content.Context;

import com.rdc.jiajiadictionary.base.BasePresenter;
import com.rdc.jiajiadictionary.data.gethistory.HistoryModel;
import com.rdc.jiajiadictionary.data.gethistory.HistoryModelInterface;


public class HistoryPresenter implements BasePresenter {
    private HistoryViewInterface mHistoryViewInterface;
    private HistoryModelInterface mHistoryModelInterface;
    @Override
    public void start() {
        getWords();
    }

    /**
     * 构造方法，view和presenter双向绑定，创建model对象引用
     * @param historyViewInterface
     * @param context
     */
    public HistoryPresenter(HistoryViewInterface historyViewInterface, Context context){
        mHistoryViewInterface = historyViewInterface;
        mHistoryViewInterface.setPresenter(this);
        mHistoryModelInterface = new HistoryModel(context);
    }

    /**
     * 从model获得历史记录的list并调用view层的方法更新ui
     */
    public void getWords(){
        mHistoryViewInterface.adaptRecycleView(mHistoryModelInterface.getWordsFromDatabase());
    }

    /**
     * 调用model层方法删除历史记录
     */
    public void deleteHistory(){
        mHistoryModelInterface.deleteHistoryFromDatabase();
    }
}
